<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>替换replace</title>
</head>
<body>
    <script>
        var str = 'baidu.com';
        //返回新的字符串
        let x = str.replace('baidu','sina');
        console.log(x);

        var str1 = 'aaaAAAAccA';
        //将大小写a都替换成百度,gi表示在全局查找g,i忽略大小写
        var newStr = str1.replace(/a/gi,'百度');
        console.log(newStr);
        //replace方法，第一个参数可以传递正则表达式
        var empty = ' 中国 西安     ';
        var newEmpty = empty.replace(/\s+/g,'');
        console.log(newEmpty);
    </script>
</body>
</html>